#include "stdafx.h"
#include "TitleManager.h"

TitleManager::TitleManager()
{
}
TitleManager::~TitleManager()
{

}

void TitleManager::loadTitleCSV()
{
	if(m_mapTitleCSV.size() != 0)
		return;
	std::string path = singleton<GameServer>::instance().GetServerPath();
	std::string filename = path + "csv/title.csv";
#ifndef _WIN32
	filename = "./csv/title.csv";
#endif
	m_csvReader.Load(filename);

	for (Int32 i = 0; i < m_csvReader.GetRowCount(); i++)
	{
		Int32 id = m_csvReader.GetInt(i,"id");
		if(m_mapTitleCSV.find(id) != m_mapTitleCSV.end())
		{
			LOGGER_ERROR("m_mapTitleCSV.find(id) != m_mapTitleCSV.end(),id:%d",id);
			return;
		}
		m_mapTitleCSV[id].id = id;
		TitleCSVInfo& info = m_mapTitleCSV[id];

		info.type = m_csvReader.GetInt(i,"type");
		info.name = m_csvReader.GetString(i,"name");
		info.description = m_csvReader.GetString(i,"description");
		info.level = m_csvReader.GetInt(i,"level");
		info.force_show = m_csvReader.GetInt(i,"force_show");
	}
}
TitleCSVInfo* TitleManager::GetTitleCSVInfo(Int32 csv_id)
{
	std::map<Int32,TitleCSVInfo>::iterator iter = m_mapTitleCSV.find(csv_id);
	if (iter == m_mapTitleCSV.end())
	{
		LOGGER_ERROR("TitleManager,iter == m_mapTitleCSV.end(),csv_id:%d",csv_id);
		return NULL;
	}
	return &(iter->second);
}